return (gc_data == &Waypoint::empty_gc_data);
}
-void
-WaypointList::waypt_add(Waypoint* wpt)
-{
- double lat_orig = wpt->latitude;
- double lon_orig = wpt->longitude;
- append(wpt);
+void Waypoint::NormalizePosition()
+{
+ double lat_orig = this->latitude;
+ double lon_orig = this->longitude;
+
+ if (this->latitude < -90.0 || this->latitude > 90.0) {
+ bool fliplon = false;
+ this->latitude = remainder(this->latitude, 360.0); // -180 <= this->latitude <= 180
+ if (this->latitude < -90.0) {
+ this->latitude = -180.0 - this->latitude;
+ fliplon = true;
+ } else if (this->latitude > 90.0) {
+ this->latitude = 180.0 - this->latitude;
+ fliplon = true;
+ }
- if (wpt->latitude < -90) {
- wpt->latitude += 180;
- } else if (wpt->latitude > +90) {
- wpt->latitude -= 180;
+ if (fliplon) {
+ if (this->longitude < 0.0) {
+ this->longitude += 180.0;
+ } else {
+ this->longitude -= 180.0;
+ }
+ }
}
- if (wpt->longitude < -180) {
- wpt->longitude += 360;
- } else if (wpt->longitude > +180) {
- wpt->longitude -= 360;
+
+ if (this->longitude < -180.0 || this->longitude >= 180.0) {
+ this->longitude = remainder(this->longitude, 360.0); // -180 <= this->longitude <= 180
+ if (this->longitude == 180.0) {
+ this->longitude = -180.0;
+ }
}
- if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
- fatal(FatalMsg() << wpt->session->name
+ if ((this->latitude < -90) || (this->latitude > 90.0))
+ fatal(FatalMsg() << this->session->name
<< "Invalid latitude" << lat_orig << "in waypoint"
- << wpt->shortname);
- if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
+ << this->shortname);
+ if ((this->longitude < -180) || (this->longitude > 180.0))
fatal(FatalMsg() << "Invalid longitude" << lon_orig << "in waypoint"
- << wpt->shortname);
+ << this->shortname);
+}
+
+void
+WaypointList::waypt_add(Waypoint* wpt)
+{
+ append(wpt);
+
+ wpt->NormalizePosition();
/*
* Some input may not have one or more of these types so we
{
append(wpt);
+ wpt->NormalizePosition();
+
if (synth && wpt->shortname.isEmpty()) {
wpt->shortname = QStringLiteral("%1%2").arg(namepart).arg(waypt_ct, number_digits, 10, QChar('0'));
wpt->wpt_flags.shortname_is_synthetic = 1;